package cn.rokhdelar.umbrsapi.management.service;

import cn.rokhdelar.umbrsapi.management.entity.SysRole;
import cn.rokhdelar.umbrsapi.management.repository.SysRoleRepo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class SysRoleService {
    private final SysRoleRepo sysRoleRepo;

    public SysRoleService(SysRoleRepo sysRoleRepo) {
        this.sysRoleRepo = sysRoleRepo;
    }

    public Page<SysRole> list(String name, Pageable pageable) {
        return sysRoleRepo.findAllByNameContaining(name, pageable);
    }

    public SysRole get(Long id) {
        return sysRoleRepo.findById(id).orElse(null);
    }

    public SysRole save(SysRole sysRole) {
        return sysRoleRepo.save(sysRole);
    }

    public void delete(Long id) {
        sysRoleRepo.deleteById(id);
    }
}
